package main

import (
	"fmt"
	"github.com/tealeg/xlsx"
)

func main() {
	//var file *xlsx.File
	//var sheet *xlsx.Sheet
	//var row *xlsx.Row
	//var cell *xlsx.Cell
	//var err error
	//
	//file = xlsx.NewFile()
	//sheet, err = file.AddSheet("Sheet1")
	//if err != nil {
	//	fmt.Printf(err.Error())
	//}
	//row = sheet.AddRow()
	//cell = row.AddCell()
	////cell.Value = "I am a cell!"
	//cell.Merge(1,2)
	//err = file.Save("MyXLSXFile.xlsx")
	//if err != nil {
	//	fmt.Printf(err.Error())
	//}


	xlsxFile, _ := xlsx.OpenFile("./Book3.xlsx")

	sheet := xlsxFile.Sheet["Sheet1"]

	//row := sheet.Rows[2]
	////从0开始，0是第一列
	//cell := row.Cells[0]
	//val :=cell.HMerge
	//
	//fmt.Println(val)


	//i 是行号，找出总行数
	for i:=0;i<5;i++ {
		//if
		//从0开始，0是第一行，1是第二行
		row := sheet.Rows[i]
		//从0开始，0是第一列
		cell := row.Cells[0]
		val :=cell.Value

		rowPre := sheet.Rows[i+1]
		//从0开始，0是第一列
		cellPre := rowPre.Cells[0]
		valPre :=cellPre.Value

		if val == valPre {
			cell.Merge(0,1)
		}



		fmt.Println(val)

	}




	//expected := "编号"
	//var val string

	//if val, err = cell.FormattedValue(); err != nil {
	//	c.Error(err)
	//}
	//c.Assert(val, Equals, expected)

	//row = sheet.Rows[2]
	//cell = row.Cells[0]
	//if val, err = cell.FormattedValue(); err != nil {
	//	c.Error(err)
	//}
	//c.Assert(val, Equals, expected)

	//row = sheet.Rows[4]
	//cell = row.Cells[1]
	////if val, err = cell.FormattedValue(); err != nil {
	//	c.Error(err)
	//}
	//c.Assert(val, Equals, "")
	//
	//if val, err = sheet.Rows[4].Cells[2].FormattedValue(); err != nil {
	//	c.Error(err)
	//}

	err := xlsxFile.Save("Book3.xlsx")
	if err != nil {
		fmt.Printf(err.Error())
	}
}